home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
4.1
/
ContextualMenus.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
5KB
|
166 lines
" NAME ContextualMenus
AUTHOR Bernard Horan <bernard@is.morgan.com>
CONTRIBUTOR Bernard Horan <bernard@is.morgan.com>
FUNCTION disable menu items
ST-VERSIONS 4.1
PREREQUISITES EmphasisedPopUpMenu
CONFLICTS
DISTRIBUTION global
VERSION 2.0
DATE September 1991
SUMMARY This category file-out contains two classes:
ContextualMenu (a subclass of EmphasisedPopUpMenu) and
ContextualMenuTracker (a subclass of MenuTracker). Combined they
provide menus with items which may appear greyed-out (or in different
emphases). The user is prohibited from selecting any of the greyed
out items. BH 25/9/92"
'From Objectworks\Smalltalk(R), Release 4.1 of 15 April 1992 on 2 September 1992 at 4:27:12 am'!
MenuTracker subclass: #ContextualMenuTracker
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'contextual menus'!
ContextualMenuTracker comment:
'I provide modified functionaility for instances of the class ContextualMenu. I only override two methods,
both of which are concerned with highlighting the menu selection. I modify my supers'' behaviour by
prohibiting the selkection of a disabled item.
Bernard Horan, 16 November 1992'!
!ContextualMenuTracker methodsFor: 'marker adjustment'!
turnMarkerOff
"Make the marker invisible, if the item is enabled"
self indexIsEnabled
ifTrue:
[self
hiliteRectangle: marker
on: gc
fColor: self foregroundColor
bColor: self backgroundColor.
self
displayExtraInformationFor: self markerIndex
fColor: self foregroundColor
bColor: self backgroundColor.
gc flush]!
turnMarkerOn
"Make the marker visible, if the item is enabled"
self indexIsEnabled
ifTrue:
[self
hiliteRectangle: marker
on: gc
fColor: self selectionForegroundColor
bColor: self selectionBackgroundColor.
self
displayExtraInformationFor: self markerIndex
fColor: self selectionForegroundColor
bColor: self selectionBackgroundColor.
gc flush]! !
!ContextualMenuTracker methodsFor: 'private'!
indexIsEnabled
^ menu fontKeys at: self markerIndex! !
EmphasisedPopUpMenu subclass: #ContextualMenu
instanceVariableNames: ''
classVariableNames: 'DisabledEmphasis EnabledEmphasis '
poolDictionaries: ''
category: 'contextual menus'!
ContextualMenu comment:
'I re-use the instance variable fontKeys to indicate the state of enabledment (?) of each of my items, i.e. an array of
Booleans. Depending on whether an item is enabled, I display it in one of two emphases. I have two class
variables EnabledEmphasis and DisabledEmphasis which are emphasis sysmbols. See class initialize for more information.
I rely on a different menuTracker, an instance of ContextualmenuTracker, which doesn''t allow a disbled item to be highlighted or selected.
Bernard Horan, 16 November 1992'!
!ContextualMenu methodsFor: 'context'!
disableIndex: anIndex
self emphasize: false at: anIndex!
enableIndex: anIndex
self emphasize: true at: anIndex! !
!ContextualMenu methodsFor: 'private'!
defaultTracker
^ContextualMenuTracker for: self!
disabledEmphasis
^DisabledEmphasis!
enabledEmphasis
^EnabledEmphasis!
valueAtSelection
"Answer the item current selected."
((selection = 0 or: [selection > values size])
or: [(self fontKeys at: selection) not])
ifTrue: [^0].
^values at: selection!
visualLabels
"Answer a TextList used to display the receiver."
| textArray |
textArray := OrderedCollection new.
labels with: self fontKeys do: [:label :fontKey |
textArray add: (Text string: label asString
emphasis: (fontKey ifTrue:[self enabledEmphasis] ifFalse:[self disabledEmphasis])) ].
^TextList new list: textArray style: self textAttributes! !
!ContextualMenu methodsFor: 'font accessing'!
fontKeys
"Answer the receiver's font key."
fontKeys isNil ifTrue:[fontKeys := Array new: self labels size withAll: true].
^ fontKeys! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
ContextualMenu class
instanceVariableNames: ''!
!ContextualMenu class methodsFor: 'class initialization'!
initialize
"ContextualMenu initialize"
EnabledEmphasis := #default.
DisabledEmphasis := #strikeout
"The strikeout emphasis seems to work best for mono screens. However here are a couple of alternatives:
EnabledEmphasis := #bold.
DisabledEmphasis := #italic.
or
EnabledEmphasis := #default.
DisabledEmphasis := Array with: #default with: #color->ColorValue lightGray"! !
!ContextualMenu class methodsFor: 'examples'!
example
"ContextualMenu example"
| text menu |
text := 'abc\def\ghi' withCRs.
menu := self labels: text lines: #(1 ).
^menu disableIndex: 2; startUp! !
ContextualMenu initialize!